﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/AdminSite.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Import Namespace="MensUnoShop.Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Appoint
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%
    UTag t = ViewData["tag"] as UTag;
 %>
<div id="main-content" class="hastable">
            <div class="title title-spacing">
			    <h2>[<%:t.TAGtitle %>]分配主類別</h2>
                將此標籤分配到主類別下
		    </div>
            <table cellspacing="0" style="width:800px;">
            <thead>
				<tr>
					<td style="width:400px">主類別清單</td>
					<td style="width:400px">已挑選清單</td>
				</tr>
			</thead>
             <tbody>
				<tr>
					<td style="width:400px; vertical-align:top;">
                        <select id="outlist" name="outlist" multiple="multiple" style="width:400px;">
                            <option>讀取中...<option>
                        </select>
                    </td>
					<td style="width:400px; vertical-align:top;">
                        <select id="inlist" name="inlist" multiple="multiple" style="width:400px;">
                            <option>讀取中...<option>
                        </select>
                    </td>
				</tr>
                <tr>
					<td style="width:400px; vertical-align:top;">
                        <input type="button" value="加入>>>" onclick="setin()" />
                    </td>
					<td style="width:400px; vertical-align:top;">
                        <input type="button" value="<<<取消" onclick="setout()" />
                    </td>
				</tr>
            </tbody>
            </table>
            <input type="button" value="回標籤清單" onclick="location.href='/Admin/TagSetup/List'" />
            <br/><br/>　
        </div>
        <div id="bk" style="width:100%;height:1000px;position:absolute; top:0px; left:0px;background-color:Black;z-index:999999;filter:alpha(opacity=50);-moz-opacity:0.5;opacity: 0.5;"></div>
        <script type="text/javascript">
            $("#bk").show();
            $.ajax({
                type: "POST",
                traditional: true,
                url: "/Admin/TagSetup/api_appoint/<%:t.TAGid %>",
                dataType: "json",
                success: function (data) {
                    if (data.code == "200") {
                        $("#outlist option").remove();
                        $("#inlist option").remove();
                        for (var i = 0; i < data.outlist.title.length; i++) {
                            $("#outlist").append('<option value="' + data.outlist.mkguid[i] + '">' + data.outlist.title[i] + '</option>');
                        }
                        for (var i = 0; i < data.inlist.title.length; i++) {
                            $("#inlist").append('<option value="' + data.inlist.mkguid[i] + '">' + data.inlist.title[i] + '</option>');
                        }
                    }
                    else
                        alert(data.response);
                    $("#bk").hide();
                },
            });
            

            function setin() {
                var json = { "mklist": [$("#outlist").val()] };
                $("#bk").show();
                $.ajax({
                    type: "POST",
                    traditional: true,
                    url: "/Admin/TagSetup/api_appointsetin/<%:t.TAGid %>",
                    data: json,
                    dataType: "json",
                    success: function (data) {
                        if (data.code == "200") {
                            $("#outlist option").remove();
                            $("#inlist option").remove();
                            for (var i = 0; i < data.outlist.title.length; i++) {
                                $("#outlist").append('<option value="' + data.outlist.mkguid[i] + '">' + data.outlist.title[i] + '</option>');
                            }
                            for (var i = 0; i < data.inlist.title.length; i++) {
                                $("#inlist").append('<option value="' + data.inlist.mkguid[i] + '">' + data.inlist.title[i] + '</option>');
                            }
                        }
                        else
                            alert(data.response);
                         $("#bk").hide();
                    }
                });
               
            }

            function setout() {
                $("#bk").show();
                var json = { "mklist": [$("#inlist").val()] };
                $.ajax({
                    type: "POST",
                    traditional: true,
                    url: "/Admin/TagSetup/api_appointsetout/<%:t.TAGid %>",
                    data: json,
                    dataType: "json",
                    success: function (data) {
                        if (data.code == "200") {
                            $("#outlist option").remove();
                            $("#inlist option").remove();
                            for (var i = 0; i < data.outlist.title.length; i++) {
                                $("#outlist").append('<option value="' + data.outlist.mkguid[i] + '">' + data.outlist.title[i] + '</option>');
                            }
                            for (var i = 0; i < data.inlist.title.length; i++) {
                                $("#inlist").append('<option value="' + data.inlist.mkguid[i] + '">' + data.inlist.title[i] + '</option>');
                            }
                        }
                        else
                            alert(data.response);
                             $("#bk").hide();
                    }
                });
            }
        </script></asp:Content>
